<template>
    <el-form
        label-width="90px"
        :model="formLabelAlign"
        ref="ruleForm"
    >
        <el-form-item label="版本号">
            <el-input
                v-model="formLabelAlign.ver"
            > </el-input>
        </el-form-item>

        <el-form-item label="版本内容">
            <el-input
                type="textarea"
                :rows="3"
                v-model="formLabelAlign.content"
            > </el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submit">立即提交</el-button>
        </el-form-item>

    </el-form>
</template>

<script>
    import {versionEdit, versionAdminDetail,versionAdd,} from '@/api/version'

    export default {
        name: "versionEdit",
        data() {
            return {
                formLabelAlign:{
                    ver:'',
                    content:'',
                },
                version_id:'',
            }
        },
        methods: {
            openMask(version_id){
                this.version_id = version_id
                this.formLabelAlign = {
                    ver:'',
                    content:'',
                }

                if(this.version_id) this.getDetail()
            },
            getDetail() {
                versionAdminDetail(this.version_id)
                    .then(res=>{
                        if(Number(res.code)===0){
                            let data = res.data
                            Object.assign(this.formLabelAlign,{
                                content:data.content,
                                ver:data.ver,
                            })
                        }else{
                            this.$Alert({ message:res.msg, type:'error' })
                        }
                    })
            },
            submit(){
                let formLabelAlign = this.formLabelAlign
                let params = {
                    content:formLabelAlign.content,
                    ver:formLabelAlign.ver,
                }

                if(this.version_id){
                    versionEdit(this.version_id,params)
                        .then(res=>this.resultHandle(res))
                }else{
                    versionAdd(params)
                        .then(res=>this.resultHandle(res))
                }

            },
            resultHandle(res){
                if(Number(res.code)===0){
                    this.$Alert({
                        message:res.msg,
                        type:'success',
                        callback:()=>this.$emit('on-success','')
                    })
                }else{
                    this.$Alert({ message:res.msg, type:'error' })
                }
            },
        },
    }
</script>

<style scoped lang="less">

</style>
